package com.hk.core.autoconfigure.authentication.security.servlet;

import com.hk.core.authentication.security.SpringSecurityContext;
import com.hk.core.autoconfigure.authentication.AuthenticationProperties;
import com.hk.core.autoconfigure.authentication.CommonSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;


/**
 * @author Kevin
 */
@AutoConfiguration
@ConditionalOnClass(value = {SpringSecurityContext.class})
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@EnableConfigurationProperties(AuthenticationProperties.class)
@ImportAutoConfiguration(value = {CommonSecurityAutoConfiguration.class})
@EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
public class SecurityAuthenticationAutoConfiguration {


//    /**
//     * <p>
//     * 默认短信发送配置
//     * </p>
//     *
//     * <p>
//     * 必须要在 application.yml 配置文件中配置 hk.authentication.sms.enabled = true 才会有效
//     * </p>
//     *
//     * @return
//     */
//    @Configuration
//    @ConditionalOnProperty(prefix = "hk.authentication.sms", name = "enabled", havingValue = "true")
//    protected class SmsAutoConfiguration {
//
//        @Bean
//        @ConditionalOnMissingBean(SmsSender.class)
//        public SmsSender<?> defaultSmsCodeSender() {
//            return new LoggerSmsSender();
//        }
//
//        @Bean("smsValidateCodeGenerator")
//        @ConditionalOnMissingBean(DefaultValidateCodeGenerator.class)
//        public ValidateCodeGenerator<ValidateCode> validateCodeGenerator() {
//            AuthenticationProperties.SMSProperties sms = properties.getSms();
//            DefaultValidateCodeGenerator codeGenerator = new DefaultValidateCodeGenerator();
//            codeGenerator.setCodeLength(sms.getCodeLength());
//            codeGenerator.setExpireSends(codeGenerator.getExpireSends());
//            return codeGenerator;
//        }
//
//        @Autowired(required = false)
//        private ValidateCodeStrategy validateCodeStrategy;
//
////        @Bean("smsValidateCodeProcessor")
////        public ValidateCodeProcessor validateCodeProcessor(SmsSender<?> smsCodeSender, ValidateCodeGenerator<ValidateCode> validateCodeGenerator) {
////            AuthenticationProperties.SMSProperties sms = properties.getSms();
////             smsCodeProcessor = new SmsCodeProcessor(validateCodeGenerator, smsCodeSender,
////                    sms.getPhoneParameter(), sms.getCodeParameter());
////            if (null != validateCodeStrategy) {
////                smsCodeProcessor.setValidateCodeStrategy(validateCodeStrategy);
////            }
////            return smsCodeProcessor;
////        }
//    }

}
